
package Gui;

import Logica.CreacionInformacion;
import Logica.EdicionInformacion;
import Logica.EliminacionInformacion;
import Oracle.OracleMethods;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author odmaestrams
 */
public class VentaKioscosGUI extends javax.swing.JFrame {

    private SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
    private String fechaAnterior = "";
    private String rifClienteAnt = "";
    private Integer nroKioscoAnt = null;
    private Integer montoAnterior = null;
    
    /** Creates new form VentaKioscosGUI */
    public VentaKioscosGUI() throws SQLException {
        initComponents();
        this.setLocationRelativeTo(null);
        mostrarInfoVentas();
        llenarCamposInformacion();
        this.back_Button.requestFocus();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    public final void llenarCamposInformacion() {
        try {
            
            if((kioscosBox.getSelectedItem() == null) && (clientesBox.getSelectedItem() == null)){
                ArrayList<String> infoArray = new ArrayList<String>();
                
                //Mostrar todos los materiales de vallas en el ComboBox correspondiente.
                infoArray = OracleMethods.todosLosKioscos();
                kioscosBox.addItem("Kiosco - Nombre");
                kioscosBox.setSelectedItem("Kiosco - Nombre");
                for (int i = 0; i < infoArray.size(); i++){
                    kioscosBox.addItem(infoArray.get(i));
                }
            
                infoArray = OracleMethods.todosLosClientes();
                clientesBox.addItem("RIF - Cliente");
                clientesBox.setSelectedItem("RIF - Cliente");
                for (int i = 0; i < infoArray.size(); i++){
                    clientesBox.addItem(infoArray.get(i));
                }
                
                montoField.setText("");
            }
            
        } catch (SQLException ex) {
            System.out.println(ex);
        }
    }
    
    public final void mostrarInfoVentas() throws SQLException {
        this.infoVentas_Table.removeAll();
        
        DefaultTableModel dm = new DefaultTableModel();
        dm.addColumn("Kiosco");
        dm.addColumn("RIF Cliente");
        dm.addColumn("Fecha venta");
        dm.addColumn("Monto");
        
        Connection con = OracleMethods.oracleConnection();
        Statement stmt = con.createStatement(); 
        ResultSet rs = stmt.executeQuery("SELECT * FROM ao_info_venta");
            
        while(rs.next()) { 
            Vector row = new Vector();
            row.add(rs.getString("kiosco_PK_FK"));
            row.add(rs.getString("rif_PK_FK"));
            row.add(rs.getDate("fechaVenta_PK"));
            row.add(rs.getString("montoVenta"));
            dm.addRow(row);
        }
        
        this.infoVentas_Table.setModel(dm);
        this.infoVentas_Table.setVisible(true);
        
        stmt.close();
        rs.close();
        con.close();
    }
    
    public void limpiarCampos() {
        this.registrarButton.setText("Registrar");
        kioscosBox.setSelectedItem("Kiosco - Nombre");
        clientesBox.setSelectedItem("RIF - Cliente");
        fechaVentaC.setDate(null);
        montoField.setText("");
        kioscosBox.setEnabled(false);
        clientesBox.setEnabled(false);
        fechaVentaC.setEnabled(false);
        montoField.setEditable(false);
        this.registrarButton.setEnabled(true);
    }
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        infoVentas_Table = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        kioscosBox = new javax.swing.JComboBox();
        clientesBox = new javax.swing.JComboBox();
        montoField = new javax.swing.JTextField();
        fechaVentaC = new com.toedter.calendar.JDateChooser();
        jLabel10 = new javax.swing.JLabel();
        back_Button = new javax.swing.JButton();
        registrarButton = new javax.swing.JButton();
        editarButton = new javax.swing.JButton();
        borrarButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 550));
        setResizable(false);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Venta de kioscos"));
        jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel1MouseClicked(evt);
            }
        });

        jPanel2.setLayout(null);

        infoVentas_Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        infoVentas_Table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                infoVentas_TableMouseReleased(evt);
            }
        });
        infoVentas_Table.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                infoVentas_TableFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(infoVentas_Table);

        jPanel2.add(jScrollPane1);
        jScrollPane1.setBounds(0, 0, 380, 350);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Informacion de venta"));
        jPanel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel3MouseClicked(evt);
            }
        });

        jLabel1.setText("Kiosco:");

        jLabel2.setText("Cliente:");

        jLabel3.setText("Fecha venta:");

        jLabel4.setText("Monto:");

        kioscosBox.setEnabled(false);

        clientesBox.setEnabled(false);

        montoField.setEditable(false);
        montoField.setMaximumSize(new java.awt.Dimension(20, 28));
        montoField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                montoFieldKeyTyped(evt);
            }
        });

        fechaVentaC.setEnabled(false);

        jLabel10.setFont(new java.awt.Font("Lucida Grande", 0, 10));
        jLabel10.setText("Bs.");

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel3)
                    .add(jLabel2)
                    .add(jLabel1)
                    .add(jLabel4))
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(montoField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel10))
                    .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(kioscosBox, 0, 180, Short.MAX_VALUE)
                        .add(clientesBox, 0, 180, Short.MAX_VALUE)
                        .add(fechaVentaC, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 150, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(36, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(kioscosBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(clientesBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(fechaVentaC, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(montoField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel10))
                .add(200, 200, 200))
        );

        jPanel2.add(jPanel3);
        jPanel3.setBounds(380, 0, 320, 350);

        jTabbedPane1.addTab("Informacion ventas", jPanel2);

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE)
                .addContainerGap())
        );

        back_Button.setText("Atras");
        back_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                back_ButtonActionPerformed(evt);
            }
        });

        registrarButton.setText("Registrar");
        registrarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                registrarButtonActionPerformed(evt);
            }
        });

        editarButton.setText("Editar");
        editarButton.setEnabled(false);
        editarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarButtonActionPerformed(evt);
            }
        });

        borrarButton.setText("Eliminar");
        borrarButton.setEnabled(false);
        borrarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                borrarButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(registrarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(editarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(borrarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 404, Short.MAX_VALUE)
                        .add(back_Button, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(back_Button, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(registrarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(editarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(borrarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void back_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_back_ButtonActionPerformed
    this.dispose();
}//GEN-LAST:event_back_ButtonActionPerformed

private void infoVentas_TableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infoVentas_TableMouseReleased
    int row = this.infoVentas_Table.getSelectedRow();
    String infoKiosco = (String) this.infoVentas_Table.getModel().getValueAt(row, 0).toString();
    String infoCliente = (String) this.infoVentas_Table.getModel().getValueAt(row, 1).toString();
    
    for (int i = 0; i < kioscosBox.getItemCount(); i++){
        if (kioscosBox.getItemAt(i).toString().substring(0, kioscosBox.getItemAt(i).toString().indexOf(" ")).equals(infoKiosco)){
            kioscosBox.setSelectedItem(kioscosBox.getItemAt(i));
            break;
        }
    }
    
    for (int i = 0; i < clientesBox.getItemCount(); i++){
        if (clientesBox.getItemAt(i).toString().substring(0, clientesBox.getItemAt(i).toString().indexOf(" ")).equals(infoCliente)){
            clientesBox.setSelectedItem(clientesBox.getItemAt(i));
            break;
        }
    }
    
    fechaVentaC.setDate(Date.valueOf(this.infoVentas_Table.getModel().getValueAt(row, 2).toString()));
    montoField.setText((String) this.infoVentas_Table.getModel().getValueAt(row, 3).toString());
    
    editarButton.setEnabled(true);
    borrarButton.setEnabled(true);
    
    
}//GEN-LAST:event_infoVentas_TableMouseReleased

private void registrarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_registrarButtonActionPerformed
    if (this.registrarButton.getText().equals("Registrar")){
        this.limpiarCampos();
        kioscosBox.setEnabled(true);
        kioscosBox.setSelectedItem("Kiosco - Nombre");
        clientesBox.setEnabled(true);
        clientesBox.setSelectedItem("RIF - Cliente");
        fechaVentaC.setEnabled(true);
        montoField.setEditable(true);
        registrarButton.setText("Confirmar");
        this.borrarButton.setEnabled(false);
        this.editarButton.setEnabled(false);
    }
    else{
        
        if((clientesBox.getSelectedItem().equals("RIF - Cliente")) || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre")) 
            || (fechaVentaC.getDate() == null) || (montoField.getText().equals(""))){
            
            JOptionPane.showMessageDialog(this, "Error, campos incompletos o erroneos");
            
        }      
        else{      
        
            String fechaVenta = fecha.format(fechaVentaC.getDate());
            String rifCliente = clientesBox.getSelectedItem().toString().substring(0, clientesBox.getSelectedItem().toString().indexOf(" "));
            Integer nroKiosco = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0, kioscosBox.getSelectedItem().toString().indexOf(" ")));
            Integer montoVenta = Integer.parseInt(montoField.getText());
            registrarButton.setText("Registrar");
            this.borrarButton.setEnabled(false);
            this.editarButton.setEnabled(false);
        
            try {
                int resultado = CreacionInformacion.crearVentaKiosco(fechaVenta, nroKiosco, rifCliente, montoVenta);
                if (resultado != 0){
                    this.mostrarInfoVentas();
                    JOptionPane.showMessageDialog(this, "Operacion Exitosa");
                    limpiarCampos();
                }
            } catch (SQLException ex) {
                System.out.println(ex);
            }
        }
    }
}//GEN-LAST:event_registrarButtonActionPerformed

private void editarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarButtonActionPerformed
    if (editarButton.getText().equals("Editar")){
        kioscosBox.setEnabled(true);
        clientesBox.setEnabled(true);
        fechaVentaC.setEnabled(true);
        montoField.setEditable(true);
        editarButton.setText("Confirmar");
        registrarButton.setEnabled(false);
        borrarButton.setEnabled(false);
        fechaAnterior = fecha.format(fechaVentaC.getDate());
        rifClienteAnt = clientesBox.getSelectedItem().toString().substring(0, clientesBox.getSelectedItem().toString().indexOf(" "));
        nroKioscoAnt = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0, kioscosBox.getSelectedItem().toString().indexOf(" ")));
        montoAnterior = Integer.parseInt(montoField.getText());
    }
    else {
        if((clientesBox.getSelectedItem().equals("RIF - Cliente")) || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre")) 
            || (fechaVentaC.getDate() == null) || (montoField.getText().equals(""))){
            
            JOptionPane.showMessageDialog(this, "Error, campos incompletos o erroneos");
            
        }      
        else{ 
            
            kioscosBox.setEnabled(false);
            clientesBox.setEnabled(false);
            fechaVentaC.setEnabled(false);
            montoField.setEditable(false);
            editarButton.setText("Editar");
            registrarButton.setEnabled(true);
            borrarButton.setEnabled(true);
            String fechaVenta = fecha.format(fechaVentaC.getDate());
            Integer montoVenta = Integer.parseInt(montoField.getText());
            Integer nroKiosco = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0, kioscosBox.getSelectedItem().toString().indexOf(" ")));
            String rifCliente = clientesBox.getSelectedItem().toString().substring(0, clientesBox.getSelectedItem().toString().indexOf(" "));
                
            try {
                int resultado = EdicionInformacion.editarVenta(fechaAnterior, fechaVenta, montoVenta, nroKiosco, rifCliente, rifClienteAnt, nroKioscoAnt, montoAnterior);

                if (resultado != 0){
                    JOptionPane.showMessageDialog(this, "Edición Exitosa");
                    this.mostrarInfoVentas();
                }
            } catch (SQLException ex) {
                System.out.println(ex);
            }
        }
    }
}//GEN-LAST:event_editarButtonActionPerformed

private void borrarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_borrarButtonActionPerformed
    int confirmacion = JOptionPane.showConfirmDialog(this, "¿Desea eliminar ésta informacion de venta?");

    if(confirmacion == 0){
        String fechaVenta = fecha.format(fechaVentaC.getDate());
        Integer montoVenta = Integer.parseInt(montoField.getText());
        Integer nroKiosco = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0, kioscosBox.getSelectedItem().toString().indexOf(" ")));
        String rifCliente = clientesBox.getSelectedItem().toString().substring(0, clientesBox.getSelectedItem().toString().indexOf(" "));
        
        try {
            int resultado = EliminacionInformacion.eliminarVentaKiosco(fechaVenta, nroKiosco, rifCliente);
            if (resultado != 0){
                JOptionPane.showMessageDialog(this, "Operacion Exitosa");
                this.mostrarInfoVentas();
                limpiarCampos();
            }
        } catch (SQLException ex) {
            System.out.println(ex);
        }   
    }
}//GEN-LAST:event_borrarButtonActionPerformed

private void infoVentas_TableFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_infoVentas_TableFocusGained
    this.infoVentas_Table.setRowSelectionAllowed(true);
    this.editarButton.setEnabled(true);
    this.borrarButton.setEnabled(true);
    this.limpiarCampos();
}//GEN-LAST:event_infoVentas_TableFocusGained

private void jPanel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel3MouseClicked
    if (this.editarButton.isEnabled() || this.borrarButton.isEnabled()){
        this.back_Button.requestFocus();
        this.editarButton.setEnabled(false);
        this.borrarButton.setEnabled(false);
        this.infoVentas_Table.setRowSelectionAllowed(false);
        limpiarCampos();
        this.editarButton.setText("Editar");
        this.registrarButton.setText("Registrar");
    }
}//GEN-LAST:event_jPanel3MouseClicked

private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MouseClicked
    if (this.editarButton.isEnabled() || this.borrarButton.isEnabled()){
        this.back_Button.requestFocus();
        this.editarButton.setEnabled(false);
        this.borrarButton.setEnabled(false);
        this.infoVentas_Table.setRowSelectionAllowed(false);
        limpiarCampos();
        this.editarButton.setText("Editar");
        this.registrarButton.setText("Registrar");
    }
}//GEN-LAST:event_jPanel1MouseClicked

private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
    if (this.editarButton.isEnabled() || this.borrarButton.isEnabled()){
        this.back_Button.requestFocus();
        this.editarButton.setEnabled(false);
        this.borrarButton.setEnabled(false);
        this.infoVentas_Table.setRowSelectionAllowed(false);
        limpiarCampos();
        this.editarButton.setText("Editar");
        this.registrarButton.setText("Registrar");
    }
}//GEN-LAST:event_formMouseClicked

private void montoFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_montoFieldKeyTyped
    if (montoField.getText().length() > 4)
        evt.consume();
    else{
        char caracter = evt.getKeyChar();
        // Verificar si la tecla pulsada no es un digito
        if(((caracter < '0') || (caracter > '9')) && (caracter != '\b')){
            evt.consume();  // ignorar el evento de teclado
        }
    }
}//GEN-LAST:event_montoFieldKeyTyped

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton back_Button;
    private javax.swing.JButton borrarButton;
    private javax.swing.JComboBox clientesBox;
    private javax.swing.JButton editarButton;
    private com.toedter.calendar.JDateChooser fechaVentaC;
    private javax.swing.JTable infoVentas_Table;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JComboBox kioscosBox;
    private javax.swing.JTextField montoField;
    private javax.swing.JButton registrarButton;
    // End of variables declaration//GEN-END:variables
}
